﻿<!--
  
   HomeSystemEditor.xaml
  
   Copyright (c) 2007 Mike Strobel
  
   This source code is subject to the terms of the Microsoft Reciprocal License (Ms-RL).
   For details, see <http://www.opensource.org/licenses/ms-rl.html>.
  
   All other rights reserved.
  
  -->
<local:EditorBase x:Class="Supremacy.Editor.HomeSystemEditor"
             xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
             xmlns:s="http://www.startreksupremacy.com/"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:av="http://schemas.codeplex.com/wpfcontrib/xaml/presentation"
             xmlns:local="clr-namespace:Supremacy.Editor">
  <local:EditorBase.Resources>
    <DataTemplate x:Key="SinglePlanetDescriptorTemplate"
                  DataType="{x:Type s:PlanetDescriptor}">
      <Grid>
        <Ellipse x:Name="PlanetShape"
                 Width="32"
                 Height="{Binding Path=Width, RelativeSource={RelativeSource Self}}"
                 Fill="Gainsboro"
                 Stroke="Black"
                 StrokeThickness="2"
                 StrokeDashCap="Flat" />
        <!--<TextBlock x:Name="PlanetTypeText"
                   Text="{Binding Path=Type, Converter={StaticResource PlanetTypeAbbreviationConverter}}"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   FontWeight="Bold" />-->
      </Grid>
      <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding Path=IsSizeDefined}"
                     Value="False">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.StrokeDashArray"
                  Value="{Binding Source={x:Static DashStyles.Dash}, Path=Dashes}" />
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Fill"
                  Value="Transparent" />
        </DataTrigger>
        <!--<DataTrigger Binding="{Binding Path=IsTypeDefined}"
                     Value="False">
          <Setter TargetName="PlanetTypeText"
                  Property="TextBlock.Text"
                  Value="?" />
        </DataTrigger>-->
        <DataTrigger Binding="{Binding Path=Size}"
                     Value="Tiny">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Width"
                  Value="16" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Size}"
                     Value="Small">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Width"
                  Value="24" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Size}"
                     Value="Medium">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Width"
                  Value="32" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Size}"
                     Value="Large">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Width"
                  Value="40" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Size}"
                     Value="Giant">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Width"
                  Value="54" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Size}"
                     Value="GasGiant">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Width"
                  Value="54" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Size}"
                     Value="Asteroids">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Width"
                  Value="24" />
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.StrokeDashArray"
                  Value="{Binding Source={x:Static DashStyles.Dot}, Path=Dashes}" />
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Fill"
                  Value="Transparent" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Type}"
                     Value="Barren">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Fill"
                  Value="Silver" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Type}"
                     Value="Volcanic">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Fill"
                  Value="Firebrick" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Type}"
                     Value="Desert">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Fill"
                  Value="Khaki" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Type}"
                     Value="Jungle">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Fill"
                  Value="LimeGreen" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Type}"
                     Value="Terran">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Fill"
                  Value="Green" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Type}"
                     Value="Oceanic">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Fill"
                  Value="LightSeaGreen" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Type}"
                     Value="Arctic">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Fill"
                  Value="AliceBlue" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Type}"
                     Value="Rogue">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Fill"
                  Value="Olive" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Type}"
                     Value="Crystalline">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Fill"
                  Value="BlueViolet" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Type}"
                     Value="Demon">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Fill"
                  Value="Red" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Type}"
                     Value="GasGiant">
          <Setter TargetName="PlanetShape"
                  Property="Ellipse.Fill"
                  Value="RosyBrown" />
        </DataTrigger>        
      </DataTemplate.Triggers>
    </DataTemplate>

    <DataTemplate x:Key="MultiPlanetDescriptorTemplate"
                  DataType="{x:Type s:PlanetDescriptor}">
      <StackPanel Orientation="Vertical">
        <StackPanel Orientation="Horizontal">
          <Ellipse Width="16"
                   Height="{Binding Path=Width, RelativeSource={RelativeSource Self}}"
                   HorizontalAlignment="Center"
                   Fill="Gainsboro"
                   Stroke="Black"
                   StrokeDashArray="{Binding Source={x:Static DashStyles.Dash}, Path=Dashes}"
                   StrokeThickness="2"
                   StrokeDashCap="Flat" />
          <Ellipse Width="16"
                   Height="{Binding Path=Width, RelativeSource={RelativeSource Self}}"
                   HorizontalAlignment="Center"
                   Margin="2,0,0,0"
                   Fill="Gainsboro"
                   Stroke="Black"
                   StrokeDashArray="{Binding Source={x:Static DashStyles.Dash}, Path=Dashes}"
                   StrokeThickness="2"
                   StrokeDashCap="Flat" />
          <Ellipse Width="16"
                   Height="{Binding Path=Width, RelativeSource={RelativeSource Self}}"
                   HorizontalAlignment="Center"
                   Margin="2,0,0,0"
                   Fill="Gainsboro"
                   Stroke="Black"
                   StrokeDashArray="{Binding Source={x:Static DashStyles.Dash}, Path=Dashes}"
                   StrokeThickness="2"
                   StrokeDashCap="Flat" />
        </StackPanel>
        <TextBlock HorizontalAlignment="Center"
                   FontWeight="Bold"
                   FlowDirection="LeftToRight">
          <TextBlock Text="{Binding Path=MinNumberOfPlanets}" />
          <TextBlock Text="..." />
          <TextBlock Text="{Binding Path=MaxNumberOfPlanets}" />
        </TextBlock>
      </StackPanel>
    </DataTemplate>

    <DataTemplate DataType="{x:Type s:PlanetDescriptor}">
      <ContentPresenter x:Name="ContentSite"
                        Content="{Binding}"
                        ContentTemplate="{StaticResource SinglePlanetDescriptorTemplate}" />
      <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding Path=IsSinglePlanet}"
                     Value="False">
          <Setter TargetName="ContentSite"
                  Property="ContentPresenter.ContentTemplate"
                  Value="{StaticResource MultiPlanetDescriptorTemplate}" />
        </DataTrigger>
      </DataTemplate.Triggers>
    </DataTemplate>

    <ControlTemplate x:Key="HomeSystemEditorTemplate"
                     TargetType="Control">
      <av:AutoGrid Orientation="Vertical"
                   ChildMargin="2"
                   HorizontalAlignment="Stretch">
        <av:AutoGrid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="*"
                            MinWidth="256" />
          <ColumnDefinition Width="Auto" />
        </av:AutoGrid.ColumnDefinitions>
        <av:AutoGrid.Children>
          <Label Content="Star Type:"
                 FontWeight="Bold"
                 Target="{Binding ElementName=StarTypesList}" />
          <ComboBox x:Name="StarTypesList"
                    SelectedItem="{Binding Path=StarType}" />
          <CheckBox x:Name="AutoStarTypeCheckBox"
                    Content="Auto"
                    VerticalAlignment="Center"
                    Unchecked="AutoStarTypeCheckBox_Changed"
                    Checked="AutoStarTypeCheckBox_Changed" />
          <Label Content="Inhabitants:"
                 FontWeight="Bold"
                 Target="{Binding ElementName=InhabitantsList}" />
          <ComboBox x:Name="InhabitantsList"
                    Grid.ColumnSpan="2"
                    SelectedValuePath="Key"
                    SelectedValue="{Binding Path=Inhabitants, Mode=TwoWay}"
                    TextSearch.TextPath="PluralName">
            <ComboBox.Resources>
              <DataTemplate DataType="{x:Type s:Race}">
                <TextBlock Text="{Binding Path=PluralName}" />
              </DataTemplate>
            </ComboBox.Resources>
          </ComboBox>
          <Label Content="System Bonuses:"
                 FontWeight="Bold"
                 Target="{Binding ElementName=SystemBonusSelector}" />
          <local:EnumFlagSelector x:Name="SystemBonusSelector"
                                  Grid.ColumnSpan="2"
                                  EnumType="{x:Type s:SystemBonus}"
                                  Value="{Binding Path=Bonuses, Mode=TwoWay}" />
          <Label Content="Planets:"
                 FontWeight="Bold"
                 Grid.ColumnSpan="3" />
          <StackPanel Grid.ColumnSpan="3"
                      DataContext="{Binding Path=Planets}"
                      Orientation="Vertical">
            <DockPanel LastChildFill="True">
              <StackPanel DockPanel.Dock="Bottom"
                          Orientation="Horizontal"
                          HorizontalAlignment="Center">
                <Button Content="&lt;&lt; Shift Outward"
                        Command="{x:Static ComponentCommands.MoveLeft}"
                        CommandParameter="{Binding ElementName=PlanetsList, Path=SelectedItem}"
                        Padding="3,2,3,2"
                        Margin="2,0,0,0"
                        Focusable="False" />
                <Button Content="Remove"
                        Command="{x:Static ApplicationCommands.Delete}"
                        CommandParameter="{Binding ElementName=PlanetsList, Path=SelectedItem}"
                        Padding="3,2,3,2"
                        Margin="2,0,0,0"
                        Focusable="False" />
                <Button Content="Add"
                        Command="{x:Static ApplicationCommands.New}"
                        CommandParameter="{Binding ElementName=PlanetsList, Path=SelectedItem}"
                        Padding="3,2,3,2"
                        Margin="2,0,0,0"
                        Focusable="False" />
                <Button Content="Shift Inward &gt;&gt;"
                        Command="{x:Static ComponentCommands.MoveRight}"
                        CommandParameter="{Binding ElementName=PlanetsList, Path=SelectedItem}"
                        Padding="3,2,3,2"
                        Margin="2,0,0,0"
                        Focusable="False" />
              </StackPanel>


              <ListView x:Name="PlanetsList"
                        Height="64"
                        HorizontalAlignment="Stretch"
                        FlowDirection="RightToLeft"
                        ItemsSource="{Binding}"
                        IsSynchronizedWithCurrentItem="True"
                        SelectionChanged="PlanetsList_SelectionChanged">
                <ListView.ItemsPanel>
                  <ItemsPanelTemplate>
                    <VirtualizingStackPanel IsItemsHost="True"
                                            Orientation="Horizontal"
                                            ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                            ScrollViewer.VerticalScrollBarVisibility="Disabled" />
                  </ItemsPanelTemplate>
                </ListView.ItemsPanel>
              </ListView>
            </DockPanel>
            <StackPanel x:Name="PlanetConfigPanel"
                        Orientation="Vertical"
                        Visibility="Collapsed">
              <RadioButton x:Name="SinglePlanetRadioButton"
                           GroupName="PlanetRadioGroup"
                           Content="Define a single planet."
                           Checked="PlanetRadioButton_Checked"
                           Margin="0,6,0,0" />
              <RadioButton x:Name="MultiPlanetRadioButton"
                           GroupName="PlanetRadioGroup"
                           Content="Define a placeholder for multiple computer-generated planets."
                           Checked="PlanetRadioButton_Checked"
                           Margin="0,3,0,0" />
              <StackPanel x:Name="MultiPlanetEditor"
                          Orientation="Horizontal"
                          HorizontalAlignment="Stretch"
                          Visibility="Visible"
                          Margin="0,3,0,0">
                <TextBlock Text="Generate between "
                           VerticalAlignment="Center" />
                <s:NumericUpDown x:Name="MinNumberOfPlanetsSpinner"
                                 DecimalPlaces="0"
                                 Minimum="1"
                                 Maximum="10"
                                 ValueChanged="NumberOfPlanetsSpinner_ValueChanged"
                                 VerticalAlignment="Center" />
                <TextBlock Text=" and "
                           VerticalAlignment="Center" />
                <s:NumericUpDown x:Name="MaxNumberOfPlanetsSpinner"
                                 DecimalPlaces="0"
                                 Minimum="2"
                                 Maximum="10"
                                 ValueChanged="NumberOfPlanetsSpinner_ValueChanged"
                                 VerticalAlignment="Center" />
                <TextBlock Text=" planets."
                           VerticalAlignment="Center" />
              </StackPanel>
              <av:AutoGrid x:Name="SinglePlanetEditor"
                           Orientation="Vertical"
                           ChildMargin="2"
                           HorizontalAlignment="Stretch"
                           Visibility="Collapsed"
                           Margin="0,6,0,0">
                <av:AutoGrid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="*"
                                    MinWidth="100" />
                  <ColumnDefinition Width="Auto" />
                </av:AutoGrid.ColumnDefinitions>
                <Label Content="Planet Name:"
                       FontWeight="Bold"
                       Target="{Binding ElementName=PlanetNameText}" />
                <TextBox x:Name="PlanetNameText"
                         Text="{Binding Path=Name, Mode=TwoWay}"
                         IsEnabled="{Binding Path=IsNameDefined}" />
                <CheckBox x:Name="AutoPlanetNameCheckBox"
                          Content="Auto"
                          VerticalAlignment="Center"
                          IsChecked="False"
                          Unchecked="AutoPlanetNameCheckBox_Changed"
                          Checked="AutoPlanetNameCheckBox_Changed" />
                <Label Content="Planet Type:"
                       FontWeight="Bold"
                       Target="{Binding ElementName=PlanetTypesList}" />
                <ComboBox x:Name="PlanetTypesList"
                          SelectedItem="{Binding Path=Type, Mode=TwoWay}"
                          IsEnabled="{Binding Path=IsTypeDefined}"
                          SelectionChanged="PlanetTypesList_SelectionChanged" />
                <CheckBox x:Name="AutoPlanetTypeCheckBox"
                          Content="Auto"
                          VerticalAlignment="Center"
                          Unchecked="AutoPlanetTypeCheckBox_Changed"
                          Checked="AutoPlanetTypeCheckBox_Changed" />
                <Label Content="Planet Size:"
                       FontWeight="Bold"
                       Target="{Binding ElementName=PlanetSizeList}" />
                <ComboBox x:Name="PlanetSizeList"
                          SelectedItem="{Binding Path=Size, Mode=TwoWay}"
                          IsEnabled="{Binding Path=IsSizeDefined}"
                          SelectionChanged="PlanetSizeList_SelectionChanged" />
                <CheckBox x:Name="AutoPlanetSizeCheckBox"
                          Content="Auto"
                          VerticalAlignment="Center"
                          Unchecked="AutoPlanetSizeCheckBox_Changed"
                          Checked="AutoPlanetSizeCheckBox_Changed" />
                <Label Content="Planet Bonuses:"
                       FontWeight="Bold"
                       Target="{Binding ElementName=PlanetBonusSelector}" />
                <local:EnumFlagSelector x:Name="PlanetBonusSelector"
                                        Grid.ColumnSpan="2"
                                        EnumType="{x:Type s:PlanetBonus}"
                                        Value="{Binding Path=Bonuses, Mode=TwoWay}" />
              </av:AutoGrid>
            </StackPanel>
          </StackPanel>
        </av:AutoGrid.Children>
      </av:AutoGrid>
      <ControlTemplate.Triggers>
        <Trigger SourceName="SinglePlanetRadioButton"
                 Property="IsChecked"
                 Value="True">
          <Setter TargetName="SinglePlanetEditor"
                  Property="Visibility"
                  Value="Visible" />
          <Setter TargetName="MultiPlanetEditor"
                  Property="Visibility"
                  Value="Collapsed" />
        </Trigger>
        <DataTrigger Binding="{Binding Path=IsNameDefined}"
                     Value="True">
          <Setter TargetName="AutoPlanetNameCheckBox"
                  Property="IsChecked"
                  Value="true" />
        </DataTrigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>

  </local:EditorBase.Resources>

  <local:EditorBase.Content>
    <Control HorizontalContentAlignment="Stretch"
             HorizontalAlignment="Stretch"
             DataContext="{Binding Path=DataContext, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:HomeSystemEditor}}}"
             Template="{StaticResource HomeSystemEditorTemplate}" />
  </local:EditorBase.Content>

</local:EditorBase>